<?php

namespace addons\xapply\controller;

use addons\xapply\Base;

class Login extends Base
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 登录接口
     * url: http://域名/addons/xapply/login
     * doc: http://lutui.net/doc/app/login.html
     */
    public function index()
    {
        $account = $this->request->post('username');
        $password = $this->request->post('password');
        if (!$account || !$password) {
            return json(['error' => '请输入账号密码']);
        }
        $ret = $this->auth->login($account, $password);
        if ($ret) {
            $user = $this->auth->getUserinfo();
            return json(['error' => '', 'token' => $user['token']]);
        }
        return json(['error' => $this->auth->getError()]);
    }
}
